package com.qfedu.java1234.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qfedu.java1234.entity.bo.Menu;
import com.qfedu.java1234.mapper.MenuMapper;
import com.qfedu.java1234.service.MenuService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu>
        implements MenuService {

    @Override
    public List<Menu> buildTreeMenu(List<Menu> sysMenuList) {
        List<Menu> resultMenuList = new ArrayList<>();
        for (Menu sysMenu : sysMenuList) {
            // 寻找子节点
            for (Menu e : sysMenuList) {
                if (e.getParentId() == sysMenu.getId()) {
                    sysMenu.getChildren().add(e);
                }
            }

            // 判断父节点，添加到集合
            if (sysMenu.getParentId() == 0L) {
                resultMenuList.add(sysMenu);
            }
        }

        return resultMenuList;
    }
}




